import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  // 主搜索页面（无导航布局）
  {
    path: '/',
    name: 'DocumentSearch',
    component: () => import('@/views/DocumentSearch.vue'),
    meta: { title: '文档检索', showInMenu: false }
  },
  // 文档预览页面（无导航布局）
  {
    path: '/preview/:id',
    name: 'DocumentPreview',
    component: () => import('@/views/DocumentPreview.vue'),
    meta: { title: '文档预览', showInMenu: false }
  },
  // 管理功能页面（带侧边栏布局，弱化显示）
  {
    path: '/admin',
    name: 'AdminLayout',
    component: () => import('@/components/Layout.vue'),
    redirect: '/admin/upload',
    meta: { title: '管理功能' },
    children: [
      {
        path: '/admin/upload',
        name: 'DocumentUpload',
        component: () => import('@/views/Documents.vue'),
        meta: { title: '文档上传', icon: 'Upload', showInMenu: true }
      },
      {
        path: '/admin/manage',
        name: 'DocumentManage',
        component: () => import('@/views/Documents.vue'),
        meta: { title: '文档管理', icon: 'Document', showInMenu: true }
      },
      {
        path: '/admin/statistics',
        name: 'Statistics',
        component: () => import('@/views/Analytics.vue'),
        meta: { title: '使用统计', icon: 'DataLine', showInMenu: true }
      },
      {
        path: '/admin/settings',
        name: 'AdminSettings',
        component: () => import('@/views/Settings.vue'),
        meta: { title: '系统设置', icon: 'Setting', showInMenu: true }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta && to.meta.title) {
    document.title = `${to.meta.title} - 希能文档管理系统`
  }
  next()
})

export default router